<template>
  <div class="app-container profile">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="user-avatar">
              <el-avatar
                src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
              ></el-avatar>
            </div>

            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <div><i class="el-icon-user-solid"></i>用户名</div>

                <div class="pull-right">{{ user.username }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-s-custom"></i>所属角色</div>

                <div class="pull-right">{{ user.roleName }}</div>
              </li>
              <li class="list-group-item">
                <div><i class="el-icon-date"></i>创建日期</div>

                <div class="pull-right">{{ user.createdTime }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>

      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userInfo from './userInfo.vue'
import resetPwd from './resetPwd.vue'
import { getAmend } from '@/api/profile'
import { getTokenValueData } from '../../../utils/auth'
import formatTime from '@/utils/formatTime'
export default {
  components: { userInfo, resetPwd },
  data () {
    return {
      user: {
        id: 0,
        username: 'admin',
        roleName: '超级管理员',
        createdTime: '2021-10-10'
      },
      activeTab: 'userinfo'
    }
  },
  mounted () {
    this.getUser()
  },
  methods: {
    async getUser () {
      const user = getTokenValueData()
      const { data } = await getAmend(user.id)
      // this.user = data.data.data
      this.user.id = user.id
      this.user.username = data.data[0].username
      this.user.roleName = data.data[0].roleName
      this.user.createdTime = formatTime(data.data[0].createdTime)
      console.log(data)
    }

  }
}
</script>

<style lang="scss" scoped>
.el-card {
  padding-bottom: 50px;
}
.user-avatar {
  // border: 1px solid;
  margin: 0 0 30px;
  display: flex;
  justify-content: center;
  padding: 8px;
}
.profile {
  .list-group {
    list-style-type: none;
    color: #303133;
    font-size: 13px;
    .list-group-item {
      padding: 8px 0;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid rgb(201, 200, 202);
      .pull-right {
        width: 90px;
        // border: 1px solid;
        text-align: left;
      }
    }
  }
}
</style>
